package nc.ui.shhq.pub;

import nc.bs.framework.common.NCLocator;
import nc.bs.pub.billcodemanage.BillcodeGenerater;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.pub.BusinessException;
import nc.vo.pub.billcodemanage.BillCodeObjValueVO;
import nc.vo.pub.lang.UFDouble;

public class ToolKit {
	
	public static UFDouble getRate(String currtypecode){
		IUAPQueryBS iuap = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		String sql =  "select distinct rate  from bd_currrate, bd_currinfo, bd_currtype, " +
		  "(select max(crate.ratedate) ratedate, ci.pk_currinfo pk_currinfo, ctype.currtypecode currtypecode " +
		  " from bd_currinfo ci, bd_currtype ctype, bd_currrate crate " +
		  " where ci.pk_currtype = ctype.pk_currtype " +
		  " and ci.pk_currinfo = crate.pk_currinfo " +
		  " and ci.oppcurrtype = '00010000000000000001' " +
		  " group by ci.pk_currinfo, ctype.currtypecode) ta " +
		  " where ta.ratedate = bd_currrate.ratedate " +
		  " and ta.pk_currinfo = bd_currrate.pk_currinfo " +
		  " and bd_currinfo.pk_currinfo = bd_currrate.pk_currinfo " +
		  " and bd_currtype.pk_currtype = bd_currinfo.pk_currtype " +
		  " and bd_currtype.currtypecode = '" + currtypecode + "' ";
		
		try {
			Object rate = iuap.executeQuery(sql, new ColumnProcessor());
			UFDouble drate = rate==null?new UFDouble(1):new UFDouble(rate.toString());
			return drate;
		} catch (BusinessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return null;
	}
	
	public static String getYhbm(String pk_bank) throws BusinessException{
		String sql = "select bankdoccode from bd_bankdoc where pk_bankdoc = '" + pk_bank +"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getBillNO(String billTypecode, String pk_corp,
			String customBillCode, BillCodeObjValueVO vo)
			throws BusinessException {
		return new BillcodeGenerater().getBillCode(billTypecode, pk_corp,
				customBillCode, vo);
	}
	
	public static String getBzPk(String code) throws BusinessException{
		String sql = "select pk_currtype from bd_currtype where currtypecode='"+ code + "'";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getCorpPkbyGL(String pk_gl) throws BusinessException{
		String sql = "select co.pk_corp from shhq_gl gl,bd_corp co where gl.gsbm=co.unitcode and gl.pk_gl ='" +pk_gl+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getJGPkbyGL(String pk_gl) throws BusinessException{
		String sql = "select bank.pk_bankdoc from shhq_gl gl,bd_bankdoc bank where gl.yhbm=bank.bankdoccode and gl.pk_gl ='" +pk_gl+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getBankNameByPk(String pk_bank) throws BusinessException{
		String sql = "select bank.bankdocname from bd_bankdoc bank where bank.pk_bankdoc ='"+pk_bank+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getZHYTByAccount(String pk_account) throws BusinessException{
		String sql = "select zhyt from shhq_account  where pk_account ='"+pk_account+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getZHSXByAccount(String pk_account) throws BusinessException{
		String sql = "select zhsx from shhq_account  where pk_account ='"+pk_account+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getCDHBycdpk(String pk_account_b) throws BusinessException{
		String sql = "select cdh from shhq_account_b  where pk_account_b ='"+pk_account_b+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static String getYHlBByPk(String pk_banktype) throws BusinessException{
		String sql = "select banktypename from bd_banktype  where pk_banktype ='"+pk_banktype+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?"":ret.toString();
	}
	
	public static UFDouble getPriceByFp(String pk_fp)throws BusinessException{
		String sql = "select price from shhq_fp where pk_fp ='" + pk_fp+"' ";
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?new UFDouble(0):new UFDouble(ret.toString());
	}
	
	public static UFDouble getGlMny(String zh,String cdh)throws BusinessException{
		String sql = ""; 
		if(cdh!=null&&!cdh.equals("")){
			sql = "select zmje from shhq_gl where cdh ='" + cdh + "' ";
		}else{
			sql = "select zmje from shhq_gl where zh ='" + zh+"' ";
		}
		Object	ret = SHHQProxy.getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		return ret==null?new UFDouble(0):new UFDouble(ret.toString());
	}
	 
}
